using UnityEngine;

public class MathTools
{
	public static float Roll(float min, float max, float value)
	{
		if (value >= min && value < max)
		{
			return value;
		}
		float num = max - min;
		if (value >= max)
		{
			value -= num;
		}
		else if (value < min)
		{
			value += num;
		}
		return Roll(min, max, value);
	}

	public static int Roll(int min, int max, int value)
	{
		if (value >= min && value < max)
		{
			return value;
		}
		int num = max - min;
		if (value >= max)
		{
			value -= num;
		}
		else if (value < min)
		{
			value += num;
		}
		return Roll(min, max, value);
	}

	public static Vector3 World2UI(Vector3 v)
	{
		Vector2 v2 = Pools.SceneCamera.WorldToScreenPoint(v);
		return BaseUIController.GetUICamera().ScreenToWorldPoint(v2);
	}

	public static int Round2Number(int x, int n)
	{
		if (x % n > n / 2)
		{
			return x + (n - x % n);
		}
		return x - x % n;
	}

	public static int Round2Number(float x, int n)
	{
		int x2 = Mathf.RoundToInt(x);
		return Round2Number(x2, n);
	}

	public static Vector3 Clamp3(Vector3 v, Vector3 min, Vector3 max)
	{
		v.x = Mathf.Clamp(v.x, min.x, max.x);
		v.y = Mathf.Clamp(v.y, min.y, max.y);
		v.z = Mathf.Clamp(v.z, min.z, max.z);
		return v;
	}

	public static float AngleBetween(Vector3 v1, Vector3 v2)
	{
		float num = Mathf.Acos(Vector3.Dot(v1.normalized, v2.normalized));
		return 57.29578f * num;
	}

	public static Vector2[] PerpendicularVector2D(Vector2 v)
	{
		v = v.normalized;
		Vector2 vector = default(Vector2);
		Vector2 vector2 = default(Vector2);
		float x = v.x;
		float y = v.y;
		float num = Mathf.Sqrt(1f / (1f + y * y / x * x));
		float num2 = (0f - y / x) * num;
		vector.Set(num2, num);
		vector2.Set(0f - num2, 0f - num);
		return new Vector2[2]
		{
			vector,
			vector2
		};
	}
}
